package JUC;

import java.util.Date;

/**
 * @author 豆包LU
 * @date 2023/5/9 16:08
 */
public class DaemonThreadExample {

    public static void main(String[] args) throws InterruptedException {
        Thread daemonThread = new Thread(() -> {
            for (int i = 0; i < 5; i++) {
                System.out.println("当前时间：" + new Date());
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        // 将线程设置为守护线程
        daemonThread.setDaemon(true);

        // 启动线程
        daemonThread.start();

        // 判断线程是否为守护线程
        if (daemonThread.isDaemon()) {
            System.out.println("该线程为守护线程");
        } else {
            System.out.println("该线程为普通线程");
        }
        Thread.sleep(6000);
    }
}
